package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.GestureDetectorCompat;

import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private Button btn1;
    private ImageButton btn2;
    private Button btn3;

    private GestureDetectorCompat gestureDetectorCompat;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn1 = findViewById(R.id.btn_1);
        btn2 = findViewById(R.id.btn_2);
        btn3 = findViewById(R.id.btn_3);
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);
        btn3.setOnClickListener(this);
//        btn1.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Toast.makeText(MainActivity.this, "111", Toast.LENGTH_SHORT).show();
//                Log.i("TAG", "onClick: 1");
//            }
//        });

        gestureDetectorCompat = new GestureDetectorCompat(this,new MyGestureListener());

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        gestureDetectorCompat.onTouchEvent(event);
        return super.onTouchEvent(event);
    }

    @Override
    public void onClick(View view) {
        String msg = "";
        switch (view.getId()){
            case R.id.btn_1:
                msg = "btn_1被点击";
                Log.i("TAG", "onClick: 1");
                break;
            case R.id.btn_2:
                msg = "btn_2被点击";
                Log.i("TAG", "onClick: 2");
                break;
            case R.id.btn_3:
                msg = "btn_3被点击";
                Log.i("TAG", "onClick: 3");
                break;
        }
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }
}